package br.edu.ifrn.potigol.lang.nodes;

import br.edu.ifrn.potigol.lang.Context;
import br.edu.ifrn.potigol.lang.PotigolException;
import br.edu.ifrn.potigol.lang.PotigolObject;

public class VariableDefinitionNode extends Node {
	private String name;
	private Node expression;
	  
	public VariableDefinitionNode(String name, Node expression) {
		this.name = name;
		this.expression = expression;
	}

	@Override
	public PotigolObject eval(Context context) throws PotigolException {
		PotigolObject value = null;
		if (expression != null) value = expression.eval(context);
	    context.createLocal(name, value);
	    return value;
	}
}
